package com.example.orderflow.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.example.orderflow.entity.enums.PageSize;
import com.example.orderflow.entity.query.ApprovalProcessQuery;
import com.example.orderflow.entity.po.ApprovalProcess;
import com.example.orderflow.entity.vo.PaginationResultVO;
import com.example.orderflow.entity.query.SimplePage;
import com.example.orderflow.mappers.ApprovalProcessMapper;
import com.example.orderflow.service.ApprovalProcessService;
import com.example.orderflow.utils.StringTools;


/**
 *  业务接口实现
 */
@Service("approvalProcessService")
public class ApprovalProcessServiceImpl implements ApprovalProcessService {

	@Resource
	private ApprovalProcessMapper<ApprovalProcess, ApprovalProcessQuery> approvalProcessMapper;

	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<ApprovalProcess> findListByParam(ApprovalProcessQuery param) {
		return this.approvalProcessMapper.selectList(param);
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public Integer findCountByParam(ApprovalProcessQuery param) {
		return this.approvalProcessMapper.selectCount(param);
	}

	/**
	 * 分页查询方法
	 */
	@Override
	public PaginationResultVO<ApprovalProcess> findListByPage(ApprovalProcessQuery param) {
		int count = this.findCountByParam(param);
		int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

		SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
		param.setSimplePage(page);
		List<ApprovalProcess> list = this.findListByParam(param);
		PaginationResultVO<ApprovalProcess> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(), page.getPageTotal(), list);
		return result;
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(ApprovalProcess bean) {
		return this.approvalProcessMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<ApprovalProcess> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.approvalProcessMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
	@Override
	public Integer addOrUpdateBatch(List<ApprovalProcess> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return this.approvalProcessMapper.insertOrUpdateBatch(listBean);
	}

	/**
	 * 多条件更新
	 */
	@Override
	public Integer updateByParam(ApprovalProcess bean, ApprovalProcessQuery param) {
		StringTools.checkParam(param);
		return this.approvalProcessMapper.updateByParam(bean, param);
	}

	/**
	 * 多条件删除
	 */
	@Override
	public Integer deleteByParam(ApprovalProcessQuery param) {
		StringTools.checkParam(param);
		return this.approvalProcessMapper.deleteByParam(param);
	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public ApprovalProcess getApprovalProcessById(Integer id) {
		return this.approvalProcessMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updateApprovalProcessById(ApprovalProcess bean, Integer id) {
		return this.approvalProcessMapper.updateById(bean, id);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deleteApprovalProcessById(Integer id) {
		return this.approvalProcessMapper.deleteById(id);
	}
}